<template>
  <div class="template-list-component">
    <el-row :gutter="16">
      <el-col v-for="item in list" :key="item.id" :span="6" class="poster-item">
        <router-link :to="{ name: 'template', params: { id: item.id } }">
          <el-card shadow="hover" :body-style="{ padding: '0px' }">
            <div class="card-cover">
              <img v-if="item.coverImg" :src="item.coverImg" />
              <img v-else :src="defaultBg" />
              <div class="hover-item">
                <el-button size="large" type="primary">使用该模版创建</el-button>
              </div>
            </div>
            <div class="card-meta">
              <div class="card-meta-title">{{ item.title }}</div>
              <div class="description-detail">
                <span>作者：{{ item.author }}</span>
                <span class="user-number">{{ item.copiedCount }}</span>
              </div>
            </div>
          </el-card>
          <div class="tag-list">
            <el-tag v-if="item.isHot" color="red">HOT</el-tag>
            <!-- <el-tag v-if="item.isNew" color="green">NEW</el-tag> -->
          </div>
        </router-link>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { TemplateData } from '@/service/request'
import defaultBg from '@/assets/default-template-bg.png'

defineProps<{ list: TemplateData[] }>()
</script>

<style lang="scss" scoped>
.template-list-component {
  width: 100%;
  height: 100%;
}
.poster-item {
  position: relative;
  margin-bottom: 20px;

  .el-card {
    border-radius: 12px;
  }

  .card-cover {
    height: 390px;
    position: relative;
    overflow: hidden;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    .hover-item {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      display: none;
      background: rgba(0, 0, 0, 0.8);
      align-items: center;
      justify-content: center;
      border-top-left-radius: 12px;
      border-top-right-radius: 12px;
    }
  }
  &:hover .hover-item {
    display: flex;
  }

  &:hover img {
    transform: scale(1.25);
  }
  .card-cover > img {
    width: 100%;
    height: 100%;
  }

  .card-cover img {
    transition: all ease-in 0.2s;
  }

  .is-hover-shadow {
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.1);
  }

  .card-meta {
    margin: 0;
    .card-meta-title {
      color: #333;
      padding: 10px 12px;
      border-bottom: 1px solid #f2f2f2;
      font-weight: 500;
      margin-bottom: 0 !important;
    }
    .description-detail {
      display: flex;
      justify-content: space-between;
      padding: 13px 12px;
      color: #999;
      .user-number {
        font-weight: bold;
      }
    }
  }
  .tag-list {
    position: absolute;
    top: -4px;
    left: 6px;
  }
}
</style>
